//
//  HomeHeaderView.m
//  PlayCatchGame
//
//  Created by 流言 on 2018/1/15.
//  Copyright © 2018年 清正. All rights reserved.
//

#import "HomeHeaderView.h"
#import "AppHeader.h"

@interface HomeHeaderView() <SDCycleScrollViewDelegate>

@property (weak, nonatomic) IBOutlet UIView *topView;
@property (weak, nonatomic) IBOutlet UIView *bottomView;

@property(nonatomic, copy)ItemPageBlock pageBlock;


@end

@implementation HomeHeaderView


- (void)awakeFromNib {
    [super awakeFromNib];
    
    [self.topView addSubview:self.carouselScrollImage];
    [self.carouselScrollImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.topView.mas_top).offset(0);
        make.left.mas_equalTo(self.topView.mas_left).offset(0);
        make.right.mas_equalTo(self.topView.mas_right).offset(0);
        make.bottom.mas_equalTo(self.topView.mas_bottom).offset(0);
    }];
    
    [self.bottomView addSubview:self.carouselScrollTitle];
    [self.carouselScrollTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.bottomView.mas_top).offset(0);
        make.left.mas_equalTo(self.bottomView.mas_left).offset(27);
        make.right.mas_equalTo(self.bottomView.mas_right).offset(0);
        make.bottom.mas_equalTo(self.bottomView.mas_bottom).offset(0);
    }];
}

- (SDCycleScrollView *)carouselScrollImage {
    if (!_carouselScrollImage) {
        _carouselScrollImage =[SDCycleScrollView cycleScrollViewWithFrame:CGRectZero imageURLStringsGroup:@[@"defaut", @"defaut"]];
        _carouselScrollImage.delegate =self;
        _carouselScrollImage.bannerImageViewContentMode =UIViewContentModeScaleAspectFill;
        _carouselScrollImage.placeholderImage =APP_DEFAULT_IMAGE;
        _carouselScrollImage.currentPageDotColor = [UIColor whiteColor];
        _carouselScrollImage.backgroundColor =[UIColor colorWithRed:0.93 green:0.93 blue:0.93 alpha:1.00];
        _carouselScrollImage.pageDotColor =[UIColor colorWithRed:0.91 green:0.91 blue:0.91 alpha:1.00];
        _carouselScrollImage.autoScrollTimeInterval =3;
        _carouselScrollImage.cornerRadius =5.0;
    }
    return _carouselScrollImage;
}

- (SDCycleScrollView *)carouselScrollTitle {
    if (!_carouselScrollTitle) {
        NSArray *titleArray =@[@"用户王小明抓获女朋友一个", @"用户张某三抓获100元红包"];
        _carouselScrollTitle =[SDCycleScrollView cycleScrollViewWithFrame:CGRectZero imageNamesGroup:titleArray];
        _carouselScrollTitle.titlesGroup = titleArray;
        _carouselScrollTitle.userInteractionEnabled =NO;
        _carouselScrollTitle.delegate =self;
        _carouselScrollTitle.onlyDisplayText = YES;
        _carouselScrollTitle.showPageControl = NO;
        _carouselScrollTitle.autoScrollTimeInterval =2;
        _carouselScrollTitle.scrollDirection = UICollectionViewScrollDirectionVertical;
        _carouselScrollTitle.titleLabelBackgroundColor = [UIColor whiteColor];
        _carouselScrollTitle.titleLabelTextColor = APP_DEFAULT_COLOUR;
        _carouselScrollTitle.titleLabelTextFont =[UIFont systemFontOfSize:15];
    }
    return _carouselScrollTitle;
}

/** 点击图片回调 */
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
    if (self.pageBlock) {
        self.pageBlock(cycleScrollView, index);
    }
}

- (void)didPageViewBlock:(ItemPageBlock)newBlock {
    self.pageBlock = newBlock;
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
